/**
 * 这里是网络请求模块
 */

 //这里是baseURL
const baseURL = 'http://localhost:3000'
// const baseURL = 'http://vae.free.svipss.top'
// const baseURL = 'http://101.200.33.191:3000'


// 这里是发请求模块
const requestData = (url, method, data) => {
    return new Promise(function(resolve, reject) {  
      wx.request({
        url: baseURL + url,
        data: data,
        method: method,
        header: {
          cookie: wx.getStorageSync('cookies')?wx.getStorageSync('cookies').find(item => item.indexOf('MUSIC_U') !== -1):''
        },
        success: function(res) {
            resolve(res.data)
            console.log('cook',res);
            if(data.islogin1){
              console.log('我是登录请求'); 
              wx.setStorage({
                key:"cookies",
                data:res.cookies,
              })
            }
        },
        fail: function(err) {
          reject(err)
        }
      })
    })
  }

//这里是方法
  function get(url, data) {
    return requestData(url, 'GET', data)
  }
   
  function post(url, data) {
    return requestData(url, 'POST', data)
  }
   
   
    module.exports = {
    GET: get,
    POST: post
  }